package com.its.common.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;

import java.util.HashMap;

/**
 * @Author xiaxp
 * @Date 1/14/22 01:10
 * @Description
 */
public class GatewayEnvSetting implements EnvironmentPostProcessor {
    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        addDefaultPropertySource(environment);
    }

    private void addDefaultPropertySource(ConfigurableEnvironment environment) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("spring.cloud.gateway.discovery.locator.enabled", true);
        map.put("spring.main.allowBeanDefinitionOverriding", true);
        map.put("spring.main.webApplicationType", "reactive");
        map.put("logging.level.org.springframework.cloud.gateway", "warn");
        map.put("management.endpoints.web.exposure.include", "*");

        PropertySource source = new MapPropertySource("gatewayExtend", map);
        environment.getPropertySources().addLast(source);
    }
}